package org.benjamin.lending.service.impl;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.benjamin.lending.domain.entity.Template;
import org.benjamin.lending.repository.TemplateRepository;
import org.benjamin.lending.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by xywenjie on 2017/6/8.
 */
@Service
public class TemplateServiceImpl implements TemplateService {

    private final Logger logger = LogManager.getLogger();

    @Autowired
    private TemplateRepository templateRepository;

    @Override
    public Template getTemplate(String code){
        logger.info("查询模板：{}",code);
        return this.templateRepository.findOne(code);
    }

    @Override
    public void saveOrSubmitTask(Template template) {
        Template temp = this.templateRepository.findOne(template.getCode());
        if(temp == null){
            logger.info("当前模板不存在，直接进行保存");
            this.templateRepository.save(template);
        }
    }
}
